<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-jmeterTestCase-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">名称：</label>
				<div class="col-sm-8">
					<input id="caseName" name="caseName" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">threads_num：</label>
				<div class="col-sm-8">
					<input id="threadsNum" name="threadsNum" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">threads_delay：</label>
				<div class="col-sm-8">
					<input id="threadsDelay" name="threadsDelay" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">start_user_count：</label>
				<div class="col-sm-8">
					<input id="startUserCount" name="startUserCount" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">start_user_burst：</label>
				<div class="col-sm-8">
					<input id="startUserBurst" name="startUserBurst" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">stop_user_period：</label>
				<div class="col-sm-8">
					<input id="startUserPeriod" name="startUserPeriod" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">stop_user_count：</label>
				<div class="col-sm-8">
					<input id="stopUserCount" name="stopUserCount" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">stop_user_period：</label>
				<div class="col-sm-8">
					<input id="stopUserPeriod" name="stopUserPeriod" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">ramp_up：</label>
				<div class="col-sm-8">
					<input id="rampUp" name="rampUp" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">jmx脚本：</label>
				<div class="col-sm-8">
					<input id="scriptName" name="scriptName" class="form-control" type="text">
					<div class="form-group" >
						<label style="display: inline-flex; margin-left: 15px" >
							<input type="file" name="file" id="file" >
							<input type="button" id="uploadBtn" th:value="开始上传" onclick="startUpload()">
						</label>
					</div>
				</div>

			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">分配客户端：</label>
				<div class="col-sm-8">
					<select id="nodeIds" name="nodeIds" class="form-control m-b" multiple="multiple">
						<option th:each="node:${nodes}" th:text="${node.nodeName}" th:value="${node.id}" ></option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">前置测试用例id：</label>
				<div class="col-sm-8">
					<select id="prevCaseId" name="prevCaseId" class="form-control m-b" >
						<option value="" >请选择</option>
						<option th:each="item:${cases}" th:text="${item.caseName}" th:value="${item.id}" ></option>
					</select>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script type="text/javascript">
		var prefix = ctx + "jmeter/jmeterTestCase"
		$("#form-jmeterTestCase-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-jmeterTestCase-add').serialize());
	        }
	    }

		/*弹出层上传Jar*/
		function uploadJar() {
			var url = prefix+"/showUploadJar";
			$.modal.open("上传Jar至客户端", url,null,null,"上传");
		}

		function startUpload() {
			var drivenfile = $('#file')[0].files[0];

			if(drivenfile==undefined){
				$.modal.msgError("请选择脚本文件");
				return;
			}

			var formData = new FormData();
			formData.append("drivenfile", drivenfile);
			$.ajax({
				url: prefix + "/uploadjmx",
				type: 'POST',
				cache: false,
				data: formData,
				processData: false,
				contentType: false,
				success: function (result) {
					if (result.code == web_status.SUCCESS) {

							$("#threadsNum").val(result.data.threadsNum);
							$("#threadsDelay").val(result.data.threadsDelay);
							$("#startUserCount").val(result.data.startUserCount);
							$("#startUserBurst").val(result.data.startUserBurst);
							$("#startUserPeriod").val(result.data.startUserPeriod);
							$("#stopUserCount").val(result.data.stopUserCount);
							$("#stopUserPeriod").val(result.data.stopUserPeriod);
							$("#flightTime").val(result.data.flightTime);
							$("#rampUp").val(result.data.rampUp);
							$("#scriptName").val(drivenfile.name);
					} else {
						$.modal.msgError(result.msg);
					}
				}
			});
		}


		$(function () {
			//远程筛选
			$("#nodeIds").select2();
			$("#prevCaseId").select2();
		});


	</script>
</body>
</html>
